﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;

using MySql.Data.MySqlClient;
using Think.Lenovo.Com.Models.Material;

namespace Think.Lenovo.Com.DataAccess
{
    public class ReceiveMaterialInfo
    {
        public long AddReceiveMaterial(ReceiveMaterial Model)
        {
                          #region //信息

            String conn = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;

            #region//sql语句
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into ")
                .Append("tbl_receivematerial")
                .Append("(MaterialBulletin_Id, Userid, Receive, ReceiveTime,regionId) ")
                .Append("values")
                .Append("(@MaterialBulletin_Id, @Userid, @Receive, @ReceiveTime,@regionId) ");

            #endregion

            #region//Sql参数数据
            MySqlParameter[] ps = new MySqlParameter[] {
                    new MySqlParameter("@MaterialBulletin_Id",MySqlDbType.Int32),
                    new MySqlParameter("@Userid",MySqlDbType.Int32),
                    new MySqlParameter("@Receive",MySqlDbType.Int32),
                    new MySqlParameter("@ReceiveTime",MySqlDbType.DateTime),
                    new MySqlParameter("@regionId",MySqlDbType.Int32)
                };

            ps[0].Value = Model.MaterialBulletin_Id;
            ps[1].Value = Model.UserId;
            ps[2].Value = Model.Receive;
            ps[3].Value = Model.ReceiveTime;
            ps[4].Value = Model.RegionId;
            #endregion
            long id = MysqlHelper.Insert(conn, sql.ToString(), ps);
            return id;

            #endregion
        }


        public long UpdateReceive(int RegionId)
        {
            String conn = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;

            #region//sql语句
            StringBuilder sql = new StringBuilder();
            sql.Append("Update ")
                .Append("tbl_receivematerial ")
                .Append("Set Receive=@Receive, ReceiveTime=@ReceiveTime where regionid = " + RegionId);

            #endregion

            #region//Sql参数数据
            MySqlParameter[] ps = new MySqlParameter[] {
                    new MySqlParameter("@Receive",MySqlDbType.Int32),
                    new MySqlParameter("@ReceiveTime",MySqlDbType.DateTime)
                };

            ps[0].Value = 1;
            ps[1].Value =DateTime.Now;

            #endregion
            long id = MysqlHelper.Update(conn, sql.ToString(), ps);
            return id;
        }

    }
}
